package service;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import bean.Message;
import bean.Message;

public class ClienteService {
	private Socket socket;
	private ObjectOutputStream output;
	private int porta;
	private String ip;
	
	public ClienteService(String ip, int porta){
		this.ip = ip;
		this.porta = porta;
	}
	
	public Socket connect(){
		try {
			this.socket = new Socket(ip,porta);
			this.output = new ObjectOutputStream(socket.getOutputStream());
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return socket;
	}
	
	public void send(Message message){

		try {
			output.writeObject(message);
	//		System.out.println("foi 2");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
